# _*_ coding: utf-8 _*_
# @Time : 2024-01-23 22:04
# @Author : wf
import openpyxl.worksheet.worksheet
from openpyxl import Workbook

wb = Workbook()
ws: openpyxl.worksheet.worksheet.Worksheet = wb.active

# 准备数据
rows = [
    ['月份', '桃子', '西瓜', '龙眼'],
    [1, 38, 28, 29],
    [2, 52, 21, 35],
    [3, 39, 20, 69],
    [4, 51, 29, 41],
    [5, 39, 39, 31],
    [6, 30, 41, 39],
]
for row in rows:
    ws.append(row)

# 过滤
# ws.auto_filter.ref = "A1:D7"  # 选择数据范围
# ws.auto_filter.add_filter_column(1, ["39", "29", "30"])  # 选择第2列为过滤数据（下标从0开始），并勾选需要过滤的数据项
# ws.auto_filter.add_sort_condition("C2:C7", True)  # 设置排序范围，第二个参数是是否倒序，默认为否


wb.save('test5.xlsx')
